<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
  <head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2012. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>
      Code Templates Preferences
    </title>
    <link rel="stylesheet" href="../../../../book.css" charset="ISO-8859-1" type="text/css">
    <script language="JavaScript" src="PLUGINS_ROOT/org.eclipse.help/livehelp.js" type="text/javascript"> </script>
  </head>
  <body>
    <h1>
      Code Templates Preferences
    </h1>
<p>The
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.svg" alt="Opens the Code Templates preference page">
<b>Java &gt; Code Style &gt; Code Templates</b></a> preference page
lets you configure the format of newly generated code and comments.</p>



<h2>Code and Comments</h2>
<p>The code and comment page contains code templates that are used by actions that generate code. Templates contain variables that are substituted when the template is applied. Some variables are available in all templates, some are specific to templates.</p>
<table border="1" cellspacing="0" cellpadding="5" width="600" summary="Code and Comments">
	<thead>
		<tr>
			<th>
			<p>Action</p>
			</th>
			<th>
			<p>Description</p>
			</th>
			<th>
			<p>Default</p>
			</th>			
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" width="25%">
			<p>Edit...</p>
			</td>
			<td valign="top">
			<p>Opens the <a href="#code-template-dialog">Code Template dialog</a> to edit the currently selected code template.</p>
			</td>
			<td valign="top">n/a</td>
		</tr>
		<tr>
			<td valign="top">
			<p>Import...</p>
			</td>
			<td valign="top">
			<p>Imports code templates from the file system.</p>
			</td>
			<td valign="top">n/a</td>
		</tr>
		<tr>
			<td valign="top">
			<p>Export...</p>
			</td>
			<td valign="top">
			<p>Exports all selected code templates to the file system.</p>
			</td>
			<td valign="top">n/a</td>
		</tr>
		<tr>
			<td valign="top">
			<p>Export All...</p>
			</td>
			<td valign="top">
			<p>Exports all code templates to the file system.</p>
			</td>
			<td valign="top">n/a</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Automatically add comments for new methods, types, modules, packages and files</p>
			</td>
			<td valign="top">
			<p>If selected, newly generated methods, types, modules, packages and files are automatically generated with comments where appropriate. The formats of the generated comments are
			defined by the <a href="#comment-templates">Comment Templates</a>.</p>
			</td>
			<td valign="top">
			<p>Off</p>
			</td>
		</tr>		
	</tbody>
</table>


<a name="comment-templates"></a>
<h2>Comment Templates</h2>

<p>Comment templates can   contain the variable <b>${tags}</b> that will be substituted by the standard Javadoc tags (@param, @return..) for the commented element.
The 'Overriding method' comment can additionally contain the template <b>${see_to_overridden}</b></p>

<table border="1" cellspacing="0" cellpadding="5" width="600" summary="Comment Templates">
	<thead>
		<tr>
			<th>
			<p>Template Name</p>
			</th>
			<th>
			<p>Specifies</p>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" width="25%">
			<p>Files</p>
			</td>
			<td valign="top">
			<p>Header comment for new files.</p>
			<p>Note that this template can be referenced in the 'New Java File' template  with <b>${filecomment}</b>.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Types</p>
			</td>
			<td valign="top">
			<p>The comment for new types.</p>
			<p> Note that this template can be referenced in the 'New Java File' template with <b>${typecomment}</b>.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Fields</p>
			</td>
			<td valign="top">
			<p>The comment for new fields.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Constructors</p>
			</td>
			<td valign="top">
			<p>The comment for new constructors.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Methods</p>
			</td>
			<td valign="top">
			<p>The comment for new methods that do not override a method in a base class and that do not delegate to any other method.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Overriding methods</p>
			</td>
			<td valign="top">
			<p>The comment for new methods that override a method in a base class.</p>
			<p>By default, this template is empty. 
			You can add a real Javadoc comment if you want.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Delegating methods</p>
			</td>
			<td valign="top">
			<p>The comment for new methods which delegate to existing methods.</p>
			<p>Such methods can be created with the <strong>Source &gt; Generate Delegate Methods...</strong> action.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Getters</p>
			</td>
			<td valign="top">
			<p>The comment for getter methods.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Setters</p>
			</td>
			<td valign="top">
			<p>The comment for setter methods.</p>
			</td>
		</tr>
	</tbody>
</table>

<h2>Code Templates</h2>
<table border="1" cellspacing="0" cellpadding="5" width="600" summary="Code Templates">
	<thead>
		<tr>
			<th>
			<p>Template Name</p>
			</th>
			<th>
			<p>Description</p>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" width="25%">
			<p>New Java files</p>
			</td>
			<td valign="top">
			<p>Used by the New Type wizards when a new Java file is created.</p> 
			<p>The template can specify where comments are added. Note that the template can contain the variable <b>${typecomment}</b> and <b>${filecomment}</b> that will be substituted by the evaluation of the <b>Types</b> respectively <b>Files</b> comment template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Class body</p>
			</td>
			<td valign="top">
			<p>Used by the New Class wizards when a new Java class is created.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Interface body</p>
			</td>
			<td valign="top">
			<p>Used by the New Interface wizards when a new Java interface is created.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Enum body</p>
			</td>
			<td valign="top">
			<p>Used by the New Enum wizards when a new Java enum is created.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Annotation body</p>
			</td>
			<td valign="top">
			<p>Used by the New Annotation wizards when a new Java annotation is created.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Method body</p>
			</td>
			<td valign="top">
			<p>The 'Method body'  templates are used when new method with a body is created that still needs some code to complete its functionality.</p> 
			<p>It contains the variable <b>${body_statement}</b> that resolves to a return statement or/and a super-call.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Constructor body</p>
			</td>
			<td valign="top">
			<p>The 'Constructor body' templates are used when new method or constructor with body is created.</p>
			<p>It contains the variable <b>${body_statement}</b> that resolves  a super call.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Getter body</p>
			</td>
			<td valign="top">
			<p>The 'Getter body' templates are used when new getter method is created.</p>
			<p>It contains the variable <b>${body_statement}</b> that resolves to the appropriate return statement.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Setter body</p>
			</td>
			<td valign="top">
			<p>The 'Setter body' templates are used when new setter method is created.</p> 
			<p>It contains the variable <b>${body_statement}</b> that resolves to the appropriate assignment statement.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" width="25%">
			<p>Catch block body</p>
			</td>
			<td valign="top">
            <p>The 'Catch block body' template is used when a catch block body is created.</p> 
            <p>It can use the variables <b>${exception_type}</b> and <b>${exception_var}</b>.</p> 
			</td>
		</tr>
	</tbody>
</table>

<a name="code-template-dialog"></a>
<h2>Code Template Dialog</h2>

<p>The following fields and buttons appear in the dialog:</p>
<table border="1" cellspacing="0" cellpadding="5" width="100%" summary="Code Template dialog">
	<thead>
		<tr>
			<th>
			<p>Action</p>
			</th>
			<th>
			<p>Description</p>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top">
			<p>Description</p>
			</td>
			<td valign="top">
			<p>A description of the template</p>
			</td>
		</tr>
		<tr>
			<td valign="top">
			<p>Pattern</p>
			</td>
			<td valign="top">
			<p>The template pattern.</p>
			</td>
		</tr>
		<tr>
			<td valign="top">
			<p>Insert Variables...</p>
			</td>
			<td valign="top">
			<p>Displays a list of pre-defined template specific variables.</p>
			</td>
		</tr>
	</tbody>
</table>

    <p>
      <h3 class="related">Related Concepts</h3>
      <p>
      <a href="../../../../concepts/concept-template-variables.htm">Template variables</a><br>
    </p>

<p>
      <h3 class="related">Related References</h3>
      <p>
      <a href="../../../ref-menu-source.htm">Source actions</a><br>
	  <a href="../../../views/ref-java-editor.htm">Java editor</a><br>
	  <a href="../../../preferences/java/ref-preferences-editor.htm">Java editor preferences</a><br>
	  <a href="../../../preferences/java/editor/ref-preferences-templates.htm">Templates preferences</a>
    </p>
    
  </body>
</html>

